<?php

!defined('IN_HDWIKI') && exit('Access Denied');

class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('doc');
		$this->load('user');
	}
	
	function dodefault(){
		$this->dorecentupdate();
	}
	
	function dorecentupdate(){
		$page = max(1, intval($this->get[2]));
		$start_limit = ($page - 1) * $this->setting['list_recentupdate'];
		$total=100;
		$count=$_ENV['doc']->get_total_num();
		$count=($count<$total)?$count:$total;
		if($page==1){
			$list=$_ENV['doc']->get_list_cache(1,$start_limit,$this->setting['list_recentupdate']);
		}else{
			$list=$_ENV['doc']->get_list(1,$start_limit,$this->setting['list_recentupdate']);
		}
		$temcount=count($list);
		for($i=0;$i<$temcount;$i++){
			$list[$i]['time']=$list[$i]['lastedit'];
		}
		$departstr=$this->multi($count, $this->setting['list_recentupdate'], $page,'list-recentupdate');
		$this->view->assign('navtitle',$this->view->lang['recentUpdate'].'-');
		$this->view->assign("departstr",$departstr);
		$this->view->assign('type','recentupdate');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}

	function doletter(){
		if(!preg_match('/^\w$/i',$this->get[2])){
			$this->message($this->view->lang['parameterError'],'BACK',0);
		}
		$page = max(1, intval($this->get[3]));
		$start_limit = ($page - 1) * $this->setting['list_letter'];
		$total=100;
		$letter=strtolower($this->get[2]);
		$count=$_ENV['doc']->get_letter_total_num($letter);
		$count=($count<$total)?$count:$total;
		$list=$_ENV['doc']->get_list($letter,$start_limit,$this->setting['list_letter']);
		$departstr=$this->multi($count, $this->setting['list_letter'], $page,'list-letter-'.$letter);
		$this->view->assign('navtitle',$this->view->lang['letterOrderView']."{$letter}-");
		$this->view->assign("departstr",$departstr);
		$this->view->assign('letter',strtoupper($letter));
		$this->view->assign('type','letter');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}
	
	function dopopularity(){
		$page = max(1, intval($this->get[2]));
		$start_limit = ($page - 1) * $this->setting['list_popularity'];
		$total=100;
		$count=$_ENV['user']->get_total_num('',0);
		$count=($count<$total)?$count:$total;
		$list=$_ENV['user']->get_popularity_user($start_limit,$this->setting['list_popularity']);
		$departstr=$this->multi($count, $this->setting['list_popularity'], $page,'list-popularity');
		$this->view->assign('navtitle',$this->view->lang['popularity'].'-');
		$this->view->assign("departstr",$departstr);
		$this->view->assign('type','popularity');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}
	
	function doallcredit(){
		$page = max(1, intval($this->get[2]));
		$start_limit = ($page - 1) * $this->setting['list_allcredit'];
		$total=100;
		$count=$_ENV['user']->get_total_num('',0);
		$count=($count<$total)?$count:$total;	
		$list=$_ENV['user']->get_top_user($start_limit,$this->setting['list_allcredit']);		
		$departstr=$this->multi($count, $this->setting['list_allcredit'], $page,'list-allcredit');
		$this->view->assign('navtitle',$this->view->lang['allcredit'].'-');
		$this->view->assign("departstr",$departstr);
		$this->view->assign('type','allcredit');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}
	
	function doweekuserlist(){
		$page = max(1, intval($this->get[2]));
		$start_limit = ($page - 1) * $this->setting['list_weekuser'];
		$total=100;
		$count=$_ENV['user']->get_week_num();
		$count=($count<$total)?$count:$total;
		$list=$_ENV['user']->get_week_user($start_limit,$this->setting['list_weekuser']);		
		$departstr=$this->multi($count, $this->setting['list_weekuser'], $page,'list-weekuserlist');
		
		$this->view->assign('navtitle',$this->view->lang['weekuserlist'].'-');
		$this->view->assign("departstr",$departstr);
		$this->view->assign('type','weekuserlist');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}
	
	function dofocus(){
		$page = max(1, intval($this->get[2]));
		$start_limit = ($page - 1) * $this->setting['list_focus'];
		$total=100;
		$num=10;
		$count=$_ENV['doc']->get_focus_total_num();
		$count=($count<$total)?$count:$total;
		$list=$_ENV['doc']->get_focus_list($start_limit,$this->setting['list_focus']);
		$departstr=$this->multi($count, $this->setting['list_focus'], $page,'list-focus');
		$this->view->assign('navtitle',$this->view->lang['focusDoc'].'-');
		$this->view->assign("departstr",$departstr);
		$this->view->assign('type','focus');
		$this->view->assign('list',$list);
		$this->view->display('list');
	}
	
	function dorss(){
		if($this->get[2]){
			$doctype=array('focus','recentupdate');
			$langetype=array('focusDoc','recentUpdate');
			$index=array_keys($doctype,$this->get[2]);
			$num=$index[0];
			if($this->get[2]=='focus'){
				$doclist=$_ENV['doc']->get_focus_list(0,$this->setting['list_focus']);
			}else{
				$doclist=$_ENV['doc']->get_list(1,0,$this->setting['list_'.$this->get[2]] );
			}
			header("Content-Type: application/xml");
			echo "<?xml version=\"1.0\" encoding='".WIKI_CHARSET."'?>\n";
			echo "<rss version=\"2.0\">\n";
			echo "<channel>\n";
			echo "<title>".$this->view->lang[$langetype[$num]]."</title>\n";
			echo "<link>".$this->setting['site_url']."/".$this->setting['seo_prefix']."list-".$this->get[2]."</link>\n";
			echo "<description>".$this->view->lang[$langetype[$num]]."</description>\n";
			echo "<generator>".$this->setting['site_url']."</generator>\n";
			echo "<lastBuildDate>".$this->date($this->time)."</lastBuildDate>\n";
			echo "<ttl>60</ttl>\n";
			if (is_array($doclist)){
				foreach ($doclist AS $doc) {
				echo "<item>\n";
				echo "<title>".$doc['title']."</title>\n";
				echo"<link>".$this->setting['site_url']."/".$this->setting['seo_prefix']."doc-view-".$doc['did']."</link>\n";
				echo "<author>".$doc['author']."</author>\n";
				echo "<description><![CDATA[".$doc['summary']."]]></description>\n";
				echo "<pubDate>".$doc['time']."</pubDate>\n";
				echo "</item>\n";
				}
			}
			echo "</channel>\n";
			echo "</rss>\n";
		}
	}
}		
?>